home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD v2.1 / Amiga Developer CD v2.1.iso / CDTV / cdtvtools-11 / cdxl / xl.c
C/C++ Source or Header  |  1991-06-24  |  5KB  |  161 lines

  1. /*
  2.  
  3. ***********************************************************************
  4. ***
  5. ***  CDTV CDXL Example #1 - Simple but Useful
  6. ***
  7. ***     Written by Carl Sassenrath, Jan 1991
  8. ***
  9. ***     In this simple example 12 megabytes of random CDROM data are
  10. ***     transferred into two "ping-pong" buffers.  This is done by
  11. ***     creating a circular transfer list (tail connects back to head).
  12. ***     At the end of each transfer, a callback function is executed to
  13. ***     increment a counter.
  14. ***
  15. ***     Once you understand this example, it should take little time
  16. ***     to enhance it to deliver graphics, sound, text, etc. as your
  17. ***     application requires.
  18. ***
  19. ***     Read the CDXL developer notes for more information.
  20. ***
  21. ***     Compiled and Tested under SAS/C 5.10a (Lattice)
  22. ***     Compiler options: -b0  (32 bit addressing)
  23. ***
  24. * Copyright (c) 1991 Commodore Business Machines, Inc.
  25. * The source code examples included are used on the Welcome Disc.  These
  26. * examples are provided for information purposes only, on an "as is" basis.
  27. * No warranties of any nature, express or implied, are made.  Any use
  28. * of these examples is at your own risk with no liability or responsability
  29. * of any kind being assumed by Commodore, its suppliers and developers,
  30. * or their employees.
  31. *
  32. * Subject to these limitations, executables based upon these examples
  33. * may be developed and used in software for the Commodore CDTV.   All
  34. * other rights are reserved.
  35. *
  36. ***********************************************************************/
  37.  
  38.  
  39. #include <exec/types.h>
  40. #include <exec/io.h>
  41. #include "cdtv.h"
  42.  
  43. extern  struct  IOStdReq *CreateStdIO();
  44. extern  struct  MsgPort  *CreatePort();
  45.  
  46. #define FRAMES  1000
  47. #define READLEN 6
  48. #define BLKSIZE 2048
  49. #define BUFSIZE (READLEN*BLKSIZE)
  50. #define MUST(expr)  if (!(expr)) Quit(AssertFail);
  51.  
  52. int     Count = 0;
  53. char    Buf[BUFSIZE*2];
  54. char    AssertFail[] = "Assertion failed (MUST)";
  55. struct  IOStdReq *IOReq = NULL;
  56. struct  MsgPort  *IOPort = NULL;
  57. struct  MinList XLList;
  58. struct  CDXL XLNodes[2];
  59.  
  60. /***********************************************************************
  61. ***
  62. ***  Quit -- exit program and clean-up.  Return an error in needed.
  63. ***
  64. ***********************************************************************/
  65. void Quit(s)
  66.         char *s;        /* error message */
  67. {
  68.         if (IOReq && IOReq->io_Device) CloseDevice(IOReq);
  69.         if (IOReq)      DeleteStdIO(IOReq);
  70.         if (IOPort)     DeletePort(IOPort);
  71.         if (s) {printf("\nERROR: %s\n",s); exit(40);}
  72.         else exit(0);
  73. }
  74.  
  75. /***********************************************************************
  76. ***
  77. ***  Init -- initialize program and structures
  78. ***
  79. ***********************************************************************/
  80. void Init()
  81. {
  82.         MUST(IOPort = CreatePort(0,0));
  83.         MUST(IOReq = CreateStdIO(IOPort));
  84.         if (OpenDevice("cdtv.device",0,IOReq,0))
  85.                 Quit("CDTV Device will not open");
  86.  
  87. }
  88.  
  89. /***********************************************************************
  90. ***
  91. ***  SendIOR -- asynchronously execute a device command
  92. ***
  93. ***********************************************************************/
  94. void SendIOR(req,cmd,off,len,data)
  95.  
  96.         struct IOStdReq *req;
  97.         int cmd;
  98.         long off;
  99.         long len;
  100.         APTR data;
  101. {
  102.         req->io_Command = cmd;
  103.         req->io_Offset = off;
  104.         req->io_Length = len;
  105.         req->io_Data   = data;
  106.         SendIO(req);
  107. }
  108.  
  109.  
  110. /***********************************************************************
  111. ***
  112. ***  XLCall -- XL Callback function (runs as an interrupt)
  113. ***
  114. ***********************************************************************/
  115. void __interrupt XLCall()
  116. {
  117.         Count++;
  118. }
  119.  
  120.  
  121. /***********************************************************************
  122. ***
  123. ***  Main
  124. ***
  125. ***********************************************************************/
  126. main(argc,argv)
  127.         int argc;
  128.         char *argv[];
  129. {
  130.         int i;
  131.  
  132.         printf("XL Example\n");
  133.  
  134.         Init();
  135.  
  136.         /* Create the Transfer List: */
  137.         XLList.mlh_Head = (struct MinNode *)&XLList.mlh_Tail;
  138.         XLList.mlh_Tail = NULL;
  139.         XLList.mlh_TailPred = (struct MinNode *)&XLList.mlh_Head;
  140.         for (i = 0; i < 2; i++)
  141.         {
  142.                 XLNodes[i].Buffer = &Buf[i*BUFSIZE];
  143.                 XLNodes[i].Length = BUFSIZE;
  144.                 XLNodes[i].DoneFunc = XLCall;
  145.                 AddTail(&XLList,&XLNodes[i]);
  146.         }
  147.  
  148.         /* Make it a circular list: */
  149.         XLList.mlh_Head->mln_Pred = XLList.mlh_TailPred;
  150.         XLList.mlh_TailPred->mln_Succ = XLList.mlh_Head;
  151.  
  152.         /* Start the transfer: */
  153.         SendIOR(IOReq,CD_READXL,100,READLEN*FRAMES,XLList.mlh_Head);
  154.  
  155.         printf("Transferring data...\r");
  156.         while (!CheckIO(IOReq)) printf("%8ld Bytes\n",Count*BUFSIZE);
  157.         WaitIO(IOReq);
  158.  
  159.         Quit(0);
  160. }
  161.